<?php
class categoryControl extends commonControl{
	//显示栏目
	public function index(){
		$db = M('category');
		$category = $db->field("catid,cname,category.sort,pid")->all();
		$category = arr::channel($category,'catid','pid',0,0,2,'>>>');
		$this->assign('category', $category);
		$this->display();
	}
	//显示添加栏目页面
	public function add_show(){		
		$this->display();
	}
	//具体添加栏目的方法
	public function add() {
		$db = M('category');
		if($db->insert()){
			$this->success('添加栏目成功','index');
		}else{
			$this->error($this->error);
		}
	}
	//显示编辑栏目页面
	public function edit_show(){
		$db = M('category');
		$db->where = 'catid='.$_GET['catid'];
		$result = $db->find();		
		$this->assign('field', $result);
		$this->display();
	}
	//具体编辑栏目方法
	public function edit(){		
		$db = M("category");
		if ($db->save()) {
			$this->success("编辑栏目成功", "index");
		} else {
			$this->error("编辑栏目失败");
		}
	}
	//删除栏目
	public function del(){
		$catid = $_GET['catid'];
		$db = M('category');
		$db->where = 'pid='.$catid;
		$result = $db->find();		
		if($result){
			$this->error('请先删除子栏目','index');
		}else{
			$db->where = 'catid='.$catid;
			if($db->del()){
				$this->success("删除成功");
			}else{
				$this->error($this->error,'index');
			}
		}
	}
}
?>